from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

import sys

sys.path.append(r'..')
from web_base.base_page import BasePage
from page_object.login_page import LoginPage


class PersonagePage(BasePage):
    url = r'/bsams/front/asset_user/user_info.do'
    # 修改电话
    mod_phone_loc = (By.ID, 'phone')
    mod_btn_loc = (By.LINK_TEXT, '保存')

    # 修改密码
    mod_password_loc = (By.LINK_TEXT, '修改密码')
    mod_oldPassword_loc = (By.ID, 'oldPassword')
    mod_newpwd1_loc = (By.ID, 'newPassword1')
    mod_newpwd2_loc = (By.ID, 'newPassword2')
    mod_ok_loc = (By.XPATH, '//*[@id="cboxLoadedContent"]/div/div/div[2]/div[4]/div[1]')

    def mod_phone(self, phone):
        self.ele_clear(self.mod_phone_loc)
        self.input_ele(self.mod_phone_loc, phone)
        self.ele_click(self.mod_btn_loc)
        sleep(3)
        # 获取警告弹窗的内容
        text = self.get_alert_text()
        self.alert_click()
        return text

    def mod_password(self, oldpwd, newpwd1, newpwd2):
        self.ele_click(self.mod_password_loc)
        self.ele_clear(self.mod_oldPassword_loc)
        self.input_ele(self.mod_oldPassword_loc, oldpwd)
        self.ele_clear(self.mod_newpwd1_loc)
        self.input_ele(self.mod_newpwd1_loc, newpwd1)
        self.ele_clear(self.mod_newpwd2_loc)
        self.input_ele(self.mod_newpwd2_loc, newpwd2)
        self.ele_click(self.mod_ok_loc)
        sleep(3)
        # 获取警告弹窗的内容
        text = self.get_alert_text()
        self.alert_click()
        return text


if __name__ == '__main__':
    phone = '151565189'

    chrome_location = r'E:\python_pro\Win_x64_1135105_chrome-win\chrome-win\chrome.exe'
    options = webdriver.ChromeOptions()
    options.binary_location = chrome_location

    driver = webdriver.Chrome(options=options)

    login_page = LoginPage(driver)
    login_page.login()

    personage = PersonagePage(driver)
    # 测试修改手机号
    # personage.mod_phone(phone)
    # 测试修改密码
    old = '123456'
    new1 = '123456'
    new2 = '123456'
    personage.mod_password(old, new1, new2)

    driver.quit()
